package com.dhcc.bpm.modules.sandbox.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.sandbox.entity.CaseApiReturn;
import com.dhcc.bpm.modules.sandbox.service.ICaseApiReturnService;
import com.dhcc.bpm.modules.sandbox.vo.CaseApiReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * @ClassName CaseApiReturnController
 * @Description 沙箱实例API返回码表 控制器
 * @Author sjm
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@RestController
@AllArgsConstructor
@RequestMapping("bpm-sandbox/caseapireturn")
@Api(value = "沙箱实例API返回码表", tags = "沙箱实例API返回码表接口")
public class CaseApiReturnController extends BladeController {

	private ICaseApiReturnService caseApiReturnService;

	/**
	 * @Description 详情
	 * @Author sjm
	 * @Date 21:26 2020/2/21 0021
	 * @param caseApiReturn
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.sandbox.entity.CaseApiReturn>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入caseApiReturn")
	@ApiLog("沙箱实例API返回码详情")
	@Log(title = "沙箱实例API返回码详情", businessType = BusinessType.SELECT)
	public R<CaseApiReturn> detail(CaseApiReturn caseApiReturn) {
		CaseApiReturn detail = caseApiReturnService.getOne(Condition.getQueryWrapper(caseApiReturn));
		return R.data(detail);
	}

	/**
	 * @Description 分页 沙箱实例API返回码表
	 * @Author sjm
	 * @Date 21:26 2020/2/21 0021
	 * @param caseApiReturn
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.sandbox.entity.CaseApiReturn>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入caseApiReturn")
	@ApiLog("分页查询沙箱实例API返回码表")
	@Log(title = "分页查询沙箱实例API返回码表", businessType = BusinessType.SELECT)
	public R<IPage<CaseApiReturn>> list(@ApiIgnore @RequestParam Map<String, Object> caseApiReturn, Query query) {
		IPage<CaseApiReturn> pages = caseApiReturnService.page(Condition.getPage(query), Condition.getQueryWrapper(caseApiReturn, CaseApiReturn.class));
		return R.data(pages);
	}

	/**
	 * @Description 自定义分页 沙箱实例API返回码表
	 * @Author sjm
	 * @Date 21:26 2020/2/21 0021
	 * @param caseApiReturn
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.sandbox.vo.CaseApiReturnVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入caseApiReturn")
	@ApiLog("分页查询沙箱实例API返回码表")
	@Log(title = "分页查询沙箱实例API返回码表", businessType = BusinessType.SELECT)
	public R<IPage<CaseApiReturnVO>> page(CaseApiReturnVO caseApiReturn, Query query) {
		IPage<CaseApiReturnVO> pages = caseApiReturnService.selectCaseApiReturnPage(Condition.getPage(query), caseApiReturn);
		return R.data(pages);
	}

	/**
	 * @Description 新增 沙箱实例API返回码表
	 * @Author sjm
	 * @Date 21:26 2020/2/21 0021
	 * @param caseApiReturn
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入caseApiReturn")
	@ApiLog("新增沙箱实例API返回码")
	@Log(title = "新增沙箱实例API返回码", businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody CaseApiReturn caseApiReturn) {
		return R.status(caseApiReturnService.save(caseApiReturn));
	}

	/**
	 * @Description 修改 沙箱实例API返回码表
	 * @Author sjm
	 * @Date 21:26 2020/2/21 0021
	 * @param caseApiReturn
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入caseApiReturn")
	@ApiLog("修改沙箱实例API返回码")
	@Log(title = "修改沙箱实例API返回码", businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody CaseApiReturn caseApiReturn) {
		return R.status(caseApiReturnService.updateById(caseApiReturn));
	}

	/**
	 * @Description 新增或修改 沙箱实例API返回码表
	 * @Author sjm
	 * @Date 21:27 2020/2/21 0021
	 * @param caseApiReturn
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入caseApiReturn")
	@ApiLog("新增或修改沙箱实例API返回码")
	@Log(title = "新增或修改沙箱实例API返回码", businessType = BusinessType.UPDATE)
	public R submit(@Valid @RequestBody CaseApiReturn caseApiReturn) {
		return R.status(caseApiReturnService.saveOrUpdate(caseApiReturn));
	}

	/**
	 * @Description 新增或修改 沙箱实例API返回码表
	 * @Author sjm
	 * @Date 21:27 2020/2/21 0021
	 * @param apiId
	 * @param caseId
	 * @param id
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submitByCaseApi")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入apiId,caseId")
	@ApiLog("新增或修改报文")
	@Log(title = "新增或修改报文", businessType = BusinessType.UPDATE)
	public R submitByCaseApi(@ApiParam(value = "主键集合", required = true) @RequestParam Long apiId,
							 @ApiParam(value = "主键集合", required = true) @RequestParam Long caseId,
							 @ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
		CaseApiReturnVO caseApiReturn = caseApiReturnService.selectCaseApi(apiId, caseId);
		if(caseApiReturn == null){
			caseApiReturn = new CaseApiReturnVO();
			caseApiReturn.setApiId(apiId);
			caseApiReturn.setCaseId(caseId);
		}
		caseApiReturn.setReturnCodeId(id);
		return R.status(caseApiReturnService.saveOrUpdate(caseApiReturn));
	}

	/**
	 * @Description 删除 沙箱实例API返回码表
	 * @Author sjm
	 * @Date 21:27 2020/2/21 0021
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	@ApiLog("删除沙箱实例API返回码")
	@Log(title = "删除沙箱实例API返回码", businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(caseApiReturnService.removeByIds(Func.toLongList(ids)));
	}

	
}
